

let colorUtils = {

    /**
     *
     * @param r {Number}
     * @param g {Number}
     * @param b {Number}
     * @returns {string}
     */
    stringifyRgb(r,g,b){
        let rr,gg,bb;
        if (r < 16){
            rr = `0${r.toString(16)}`;
        }else{
            rr = r.toString(16);
        }
        if (g < 16){
            gg = `0${g.toString(16)}`;
        }else{
            gg = g.toString(16);
        }
        if (b < 16){
            bb = `0${b.toString(16)}`;
        }else{
            bb = b.toString(16);
        }
        return `#${rr}${gg}${bb}`;
    },

    parseRbgStr(str){
        let r = parseInt(str.slice(1,3),16);
        let g = parseInt(str.slice(3,5),16);
        let b = parseInt(str.slice(5,7),16);
        return [r,g,b];
    }
};

// console.log(colorUtils.strRgb(255,0,255));
// console.log(colorUtils.parseRbgStr('#ff00ff'));
module.exports = colorUtils;
